<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2024/8/10
  Time: 9:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>User</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
    <button class="btn btn-info"><a href="/user?method=selectUserAddPage">添加</a></button>
    <table class="table table-hover table-bordered table-condensed table-responsive table-striped">
        <tr class="success">
            <td>ID</td>
            <td>用户名</td>
            <td>密码</td>
            <td>删除</td>
            <td>修改</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="user">
            <tr>
                <td>${user.id}</td>
                <td>${user.name}</td>
                <td>${user.password}</td>
                <td><button class="alert-danger"><a href="javascript:void(0)" onclick="deleteById(${user.id})">删除</a></button></td>
                <td><button class="alert-warning"><a href="/user?method=toUpdate&id=${user.id}">编辑</a></button></td>
            </tr>
        </c:forEach>
    </table>
    <nav aria-label="Page navigation">
        <ul class="pagination">
            <c:if test="${pageInfo.pageNo==1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=1}">
                <li>
                    <a href="/user?method=selectByPage&pageNo=${pageInfo.pageNo-1}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>

            <c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
                <c:if test="${i==pageInfo.pageNo}">
                    <li class="active"><a href="#">${i}</a></li>
                </c:if>
                <c:if test="${i!=pageInfo.pageNo}">
                    <li><a href="/user?method=selectByPage&pageNo=${i}&pageSize=5">${i}</a></li>
                </c:if>
            </c:forEach>

            <c:if test="${pageInfo.pageNo==pageInfo.totalPage}">
                <li class="disabled">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=pageInfo.totalPage}">
                <li>
                    <a href="/user?method=selectByPage&pageNo=${pageInfo.pageNo+1}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
        </ul>
    </nav>
    <script>
        function deleteById (id) {
            var isDelete = confirm("您确认要删除吗？");
            if(isDelete){
                location.href = "/user?method=deleteById&id=" + id;
            }
        }
    </script>
</body>
</html>
